//
//  AboutView.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/9/29.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import UIKit

class AboutView: UIView {
    
    fileprivate let font = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
    
    let scrollView = UIScrollView()

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        scrollView.showsVerticalScrollIndicator = false
        self.addSubview(scrollView)
        
        let logoImageView = UIImageView()
        logoImageView.image = #imageLiteral(resourceName: "kamenglogo")
        scrollView.addSubview(logoImageView)
        
        let titleLabel = UILabel()
        titleLabel.text = aboutUs_title
        titleLabel.font = font
        scrollView.addSubview(titleLabel)
        
        let detailsLabel = UILabel()
        detailsLabel.text = "        " + aboutUs_details
        detailsLabel.numberOfLines = 0
        detailsLabel.font = font
        scrollView.addSubview(detailsLabel)
        
        let officialLabel = UILabel()
        officialLabel.text = aboutUs_officialWebsite
        officialLabel.font = font
        scrollView.addSubview(officialLabel)
        
        let sinaLabel = UILabel()
        sinaLabel.text = aboutUs_sinaWeibo
        sinaLabel.font = font
        scrollView.addSubview(sinaLabel)
        
        let appletsImage = UIImageView()
        appletsImage.image = UIImage.init(named: "smallProgram")
        scrollView.addSubview(appletsImage)
        
        let appletsLabel = UILabel()
        appletsLabel.text = aboutUs_applets
        appletsLabel.font = font
        scrollView.addSubview(appletsLabel)
        
        let wechatImage = UIImageView()
        wechatImage.image = UIImage.init(named: "wechatConcern")
        scrollView.addSubview(wechatImage)
        
        let wechatLabel = UILabel()
        wechatLabel.text = aboutUs_wechat
        wechatLabel.adjustsFontSizeToFitWidth = true
        wechatLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 14))
        scrollView.addSubview(wechatLabel)
        
        let serviceImage = UIImageView()
        serviceImage.image = UIImage.init(named: "wechatCustomer")
        scrollView.addSubview(serviceImage)
        
        let serviceLabel = UILabel()
        serviceLabel.text = aboutUs_service
        serviceLabel.adjustsFontSizeToFitWidth = true
        serviceLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 14))
        scrollView.addSubview(serviceLabel)
        
        let companyLabel = UILabel()
        companyLabel.text = aboutUs_company
        companyLabel.font = font
        scrollView.addSubview(companyLabel)

        let cardLabel = UILabel()
        cardLabel.text = aboutUs_card
        cardLabel.font = font
        scrollView.addSubview(cardLabel)
        
        scrollView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview().inset(UIEdgeInsets.zero)
        }
        
        logoImageView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(RATIO_H(maxNum: 20))
            make.centerX.equalToSuperview()
            make.width.height.equalTo(RATIO_H(maxNum: 80))
        }
        
        titleLabel.snp.makeConstraints { (make) in
            make.top.equalTo(logoImageView.snp.bottom).offset(RATIO_H(maxNum: 10))
            make.centerX.equalToSuperview()
            make.width.greaterThanOrEqualTo(10)
            make.height.greaterThanOrEqualTo(10)
        }
        
        detailsLabel.snp.makeConstraints { (make) in
            make.left.equalTo(self).offset(RATIO(maxNum: 20))
            make.right.equalTo(self).offset(RATIO(maxNum: -20))
            make.top.equalTo(titleLabel.snp.bottom).offset(RATIO_H(maxNum: 20))
            make.height.greaterThanOrEqualTo(10)
        }
        
        officialLabel.snp.makeConstraints { (make) in
            make.top.equalTo(detailsLabel.snp.bottom).offset(RATIO_H(maxNum: 10))
            make.left.equalTo(detailsLabel)
            make.right.equalTo(detailsLabel)
            make.height.greaterThanOrEqualTo(10)
        }
        
        sinaLabel.snp.makeConstraints { (make) in
            make.top.equalTo(officialLabel.snp.bottom).offset(RATIO_H(maxNum: 10))
            make.left.equalTo(officialLabel)
            make.right.equalTo(sinaLabel)
            make.height.greaterThanOrEqualTo(10)
        }
        
        appletsImage.snp.makeConstraints { (make) in
            make.top.equalTo(sinaLabel.snp.bottom).offset(RATIO_H(maxNum: 20))
            make.centerX.equalToSuperview()
            make.width.height.equalTo(RATIO_H(maxNum: 120))
        }
        
        appletsLabel.snp.makeConstraints { (make) in
            make.top.equalTo(appletsImage.snp.bottom).offset(RATIO_H(maxNum: 5))
            make.centerX.equalTo(appletsImage)
            make.width.greaterThanOrEqualTo(10)
            make.height.greaterThanOrEqualTo(10)
        }
        
        wechatImage.snp.makeConstraints { (make) in
            make.top.equalTo(appletsLabel.snp.bottom).offset(RATIO_H(maxNum: 10))
            make.right.equalTo(self.snp.centerX).offset(RATIO(maxNum: -10))
            make.width.height.equalTo(RATIO_H(maxNum: 120))
        }
        
        serviceImage.snp.makeConstraints { (make) in
            make.top.equalTo(wechatImage)
            make.left.equalTo(self.snp.centerX).offset(RATIO(maxNum: 10))
            make.width.height.equalTo(wechatImage)
        }
        
        wechatLabel.snp.makeConstraints { (make) in
            make.top.equalTo(wechatImage.snp.bottom).offset(RATIO_H(maxNum: 5))
            make.right.equalTo(wechatImage)
            make.width.greaterThanOrEqualTo(10)
            make.height.greaterThanOrEqualTo(10)
        }
        
        serviceLabel.snp.makeConstraints { (make) in
            make.top.equalTo(wechatLabel)
            make.left.equalTo(serviceImage)
            make.width.greaterThanOrEqualTo(10)
            make.height.greaterThanOrEqualTo(10)
        }
        
        companyLabel.snp.makeConstraints { (make) in
            make.top.equalTo(wechatLabel.snp.bottom).offset(RATIO_H(maxNum: 30))
            make.centerX.equalToSuperview()
            make.width.greaterThanOrEqualTo(10)
            make.height.greaterThanOrEqualTo(10)
        }
        
        cardLabel.snp.makeConstraints { (make) in
            make.top.equalTo(companyLabel.snp.bottom).offset(RATIO_H(maxNum: 10))
            make.centerX.equalTo(companyLabel)
            make.width.greaterThanOrEqualTo(10)
            make.height.greaterThanOrEqualTo(10)
        }
        
        self.layoutIfNeeded()
        
        scrollView.contentSize = .init(width: ScreenW, height: cardLabel.frame.maxY + RATIO_H(maxNum: 20) + StatusBarAddNavBarHeight)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
